#include<bits/stdc++.h>
using namespace std;
string s1,s2;
void before(int l1,int r1,int l2,int r2){
    if(r1<=l1 || r2<=l2) 
        return;
    int k;
    for(int i=0;i<r1;i++){
        if(s1[i]==s2[r2-1]){
            cout<<s1[i];
            k=i;
            break;
        }
    }
    before(l1,k,l2,k-l1+l2);
    before(k+1,r1,k-l1+l2,r2-1);
}
int main(){
    cin>>s1>>s2;
    before(0,s1.size(),0,s2.size());
    return 0;
}
